package com.dmgo.common;

import com.mkyong.stock.StockDailyRecord;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Created by user on 01.11.2014.
 */



@Entity
@Table(name = "station", catalog = "mkyong")
public class Station implements Serializable {
    private int stationId;
    private String stationName;
    private String stationDescription;
    private Set<Train> trains = new HashSet<Train>(0);







    public Station(String stationName, String stationDescription) {
        this.stationName = stationName;
        this.stationDescription = stationDescription;
    }


    public Station() {

    }


    public void setStationId(int stationId) {

        this.stationId = stationId;
    }

    public void setStationName(String stationName) {
        this.stationName = stationName;
    }

    public void setStationDescription(String stationDescription) {
        this.stationDescription = stationDescription;
    }

    public void setTrains(Set<Train> trains) {
        this.trains = trains;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "STATION_ID", unique = true, nullable = false)
    public int getStationId() {

        return stationId;
    }
    @Column(name = "STATION_NAME", length = 20)
    public String getStationName() {
        return stationName;
    }
    @Column(name = "STATION_DESCRIPTION", length = 200)
    public String getStationDescription() {
        return stationDescription;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "station")
    public Set<Train> getTrains() {
        return trains;
    }


    @Override
    public String toString() {
        return "Station{" +
                "stationId=" + stationId +
                ", stationName='" + stationName + '\'' +
                ", stationDescription='" + stationDescription + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Station station = (Station) o;

        if (stationId != station.stationId) return false;
        if (stationDescription != null ? !stationDescription.equals(station.stationDescription) : station.stationDescription != null)
            return false;
        if (stationName != null ? !stationName.equals(station.stationName) : station.stationName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = stationId;
        result = 31 * result + (stationName != null ? stationName.hashCode() : 0);
        result = 31 * result + (stationDescription != null ? stationDescription.hashCode() : 0);
        return result;
    }




}
